package collection.Demo03;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * @Author Miku
 * @Create 2021/4/12 15:23
 * List子接口的使用
 */
public class Test {
    public static void main(String[] args) {
        //先创建集合对象
        List list = new ArrayList();
        list.add("苹果");
        list.add("小米");
        list.add(0,"华为");
        System.out.println("元素个数"+list.size());
        System.out.println(list);

        //使用迭代器
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        //使用列表迭代器
        ListIterator listIterator = list.listIterator();
        while (listIterator.hasNext()) {
            System.out.println(listIterator.nextIndex()+":"+listIterator.next());
        }
        System.out.println("------------------------");
        while (listIterator.hasPrevious()) {
            System.out.println(listIterator.previousIndex()+":"+listIterator.previous());
        }

    }
}
